
package cn.com.pusai.common.util;

import cn.com.pusai.common.config.SysProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringUtil
{

	private static ApplicationContext ctx = null;
	private static boolean initStatus = false;

	public SpringUtil()
	{
	}

	public static synchronized void initBySelf()
	{
		if (!initStatus)
		{
			initStatus = true;
			setContext(new ClassPathXmlApplicationContext(SysProperties.SPRING_CONTEXT_FILE.split(";")));
		}
	}

	public static void setContext(ApplicationContext ctx)
	{
		ctx = ctx;
	}

	public static ApplicationContext getContext()
	{
		return ctx;
	}

	public static Object getBean(String beanName)
	{
		if (ctx == null)
			initBySelf();
		return ctx.getBean(beanName);
	}

}
